<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>分销商佣金</title>
 {template 'stourtravel/public/public_js'}
   {php echo Common::getCss('style.css,base.css,base2.css,plist.css,base_new.css,order.css'); }
   {php echo Common::getCss('ext-theme-neptune-all-debug.css','js/extjs/resources/ext-theme-neptune/'); }
   {php echo Common::getScript("jquery.buttonbox.js,choose.js,hdate/hdate.js"); }
   {php echo Common::getCss('hdate.css','js/hdate'); }

</head>
<body style="overflow:hidden">
<table class="content-tab">
   <tr>
    <td width="119px" class="content-lt-td"  valign="top">
     {template 'stourtravel/public/leftnav'}
    <!--右侧内容区-->
    </td>
    <td valign="top" class="content-rt-td" style="overflow:hidden">
		<div class="cfg-header-bar clearfix">
			<span class="select-box w150 mt-5 ml-10 fl">
				<select name="typeid" id="typeid" onchange="searchKeyword()" class="select">
                    <option value="">产品类型</option>
                    {loop $modules $module}
                       <option value="{$module['id']}">{$module['modulename']}</option>
                    {/loop}
                </select>
			</span>
			<span class="select-box w150 mt-5 ml-10 fl">
				<select name="status" id="status" onchange="searchKeyword()" class="select">
                    <option value="">结算状态</option>
                    <option value="2">未结算</option>
                    <option value="5">已结算</option>
                </select>
			</span>
            <div class="cfg-header-search derive_tb">
                <div class="fl mt-5 mr-10">时间:</div>
                <input type="text" value="" id="starttime" placeholder="开始日期" autocomplete="off" style="height: 28px;padding:0 5px" class="time_box" onclick="calendar.show({ id: this })" />

                <input type="text" id="endtime" class="time_box" placeholder="结束日期" autocomplete="off" style="height: 28px;margin-left:3px;padding:0 5px" onclick="calendar.show({ id: this })" />
            </div>
			
			<div class="cfg-header-search">
				<input type="text" id="searchkey" value="" datadef="订单号" class="search-text">
                <a href="javascript:;" class="search-btn" onclick="searchKeyword()">搜索</a>
			</div>		
			<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
            <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10 btn_excel">导出Excel</a>
		</div>	

 		<div id="product_grid_panel" class="content-nrt">
    
  		</div>
  </td>
  </tr>
 </table> 
<script>


  Ext.onReady(
    function() 
    {
		 Ext.tip.QuickTipManager.init();

        $(".btnbox").buttonBox();
        $("#searchkey").focusEffect();
		//产品store
        window.product_store=Ext.create('Ext.data.Store',{

		 fields:[
             'id',
             'addtime',
             'ordersn',
             'typename',
             'productname',
             'status',
             'total_payprice',
             'total_commission'
         ],
         proxy:{
		   type:'ajax',
		   api: {
              read: SITEURL+'{$prefix_url}/index/commission/action/read',  //读取数据的URL
			  update:SITEURL+'{$prefix_url}/index/commission/action/save',
			  destroy:SITEURL+'{$prefix_url}/index/commission/action/delete'
              },
		      reader:{
                type: 'json',   //获取数据的格式 
                root: 'lists',
                totalProperty: 'total'
                }	
	         },
		 remoteSort:true,	 
		 pageSize:30,	 	
         autoLoad:true,

		 listeners:{
             load:function( store, records, successful, eOpts )
             {
                 if(!successful){
                     ST.Util.showMsg("{__('norightmsg')}",5,1000);
                 }
                 var pageHtml=ST.Util.page(store.pageSize,store.currentPage,store.getTotalCount(),10);
                 $("#line_page").html(pageHtml);
                 window.product_grid.doLayout();
                 $(".pageContainer .pagePart a").click(function () {
                     var page = $(this).attr('page');
                     product_store.loadPage(page);
                 });

             }
		 }

		  
       });
	   
	  //产品列表 
	  window.product_grid=Ext.create('Ext.grid.Panel',{ 
	   store:product_store,
	   renderTo:'product_grid_panel',
	   border:0,
	   bodyBorder:0,
	   bodyStyle:'border-width:0px',
	   scroll:'vertical',
	   bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "没有数据了",
					items:[
                        {
                            xtype:'panel',
                            id:'listPagePanel',
                            html:'<div id="line_page"></div>'
                       },
					  {
						  xtype:'combo',
						  fieldLabel:'每页显示数量',
						  width:170,
						  labelAlign:'right',
						  forceSelection:true,
						  value:30,
						  store:{fields:['num'],data:[{num:30},{num:60},{num:100}]},
						  displayField:'num',
						  valueField:'num',
						  listeners:{
							  select:CHOOSE.changeNum
						  }
					  }
					
					],
				  listeners: {
						single: true,
						render: function(bar) {
							var items = this.items;
                            bar.insert(0,Ext.create('Ext.toolbar.Fill'));
						}
					}	
                 }), 		 			 
	   columns:[
           {
               text: '下单时间',
               width: '10%',
               dataIndex: 'addtime',
               align: 'center',
               menuDisabled: true,
               border: 0,
               sortable: false,
               renderer: function (value, metadata, record) {
                   return value;
               }
           },
           {
               text: '订单号',
               width: '10%',
               dataIndex: 'ordersn',
               align: 'center',
               menuDisabled: true,
               border: 0,
               sortable: false,
               renderer: function (value, metadata, record) {
                   return value;
               }
           },
           {
               text: '产品类型',
               width: '10%',
               dataIndex: 'typename',
               align: 'center',
               menuDisabled: true,
               sortable: false,
               renderer: function (value, metadata, record, rowIndex, colIndex) {
                   return value;
               }
           },

           {
               text: '产品名称',
               width: '30%',
               dataIndex: 'productname',
               align: 'center',
               menuDisabled: true,
               sortable: false,
               renderer: function (value, metadata, record, rowIndex, colIndex) {
                   return value;
               }
           },
           {
               text: '结算状态',
               width: '10%',
               dataIndex: 'status',
               align: 'center',
               menuDisabled: true,
               renderer: function (value, metadata, record, rowIndex, colIndex) {
                   return value == 5 ? '已结算' : '<span style="color:red">未结算</span>';
               }
           },
           {
               text: '营业收入',
               width: '10%',
               dataIndex: 'total_payprice',
               align: 'center',
               menuDisabled: true,

           },
           {
               text: '分销佣金总额',
               width: '10%',
               dataIndex: 'total_commission',
               align: 'center',
               menuDisabled: true,

           },
           {
               text: '操作',
               width: '10%',
               align: 'center',
               border: 0,
               sortable: false,
               menuDisabled: true,
               cls: 'mod-1',
               renderer: function (value, metadata, record) {

                   var ordersn = record.get('ordersn');
                   var html = "<a href='javascript:void(0);' onclick='modify(\"" + ordersn + "\")' class='btn-link va-m ml-10'>详情</a>";
                   return html;


               }
           }

             ],
			 listeners:{
		            boxready:function()
		            {
                        var height=Ext.dom.Element.getViewportHeight();
					   this.maxHeight=height-106;
					   this.doLayout();
		            },
					afterlayout:function(grid)
					{

						window.product_store.each(function(record){
				         id=record.get('id');


					   });
					   
					   var data_height=0;
					   try{
					     data_height=grid.getView().getEl().down('.x-grid-table').getHeight();
					   }catch(e)
					   {

					   }
					  var height=Ext.dom.Element.getViewportHeight();
					// console.log(data_height+'---'+height);
					  if(data_height>height-106)
					  {
						  window.has_biged=true;
						  grid.height=height-106;
					  }
					  else if(data_height<height-106)
					  {
						  if(window.has_biged)
						  {
							//delete window.product_grid.height;
							window.has_biged=false;  
							grid.doLayout();
						  }
					  }
				  }
			 },
			 plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                  clicksToEdit:2,
                  listeners:{
					 edit:function(editor, e)
					 {
						   var id=e.record.get('id');
						 //  var view_el=window.product_grid.getView().getEl();
						 // view_el.scrollBy(0,this.scroll_top,false);
						updateField(0,id,e.field,e.value,0);
						return false;
						  
					 },
					 beforeedit:function(editor,e)
					 {

						// var view_el=window.product_grid.getView().getEl();
	                     //this.scroll_top=view_el.getScrollTop();				   
	 
					 }
				 }
               })
             ],
			viewConfig:{
				enableTextSelection:true
			}
	   });
	   
	  
	  
	})
	
	//实现动态窗口大小
  Ext.EventManager.onWindowResize(function(){ 
       var height=Ext.dom.Element.getViewportHeight(); 
	   var data_height=window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
	   if(data_height>height-106)
	     window.product_grid.height=(height-106);
	   else
	      delete window.product_grid.height;
	   window.product_grid.doLayout();
	   
	 })



  //按进行搜索
  function searchKeyword() {
      var starttime = $('#starttime').val();
      var endtime = $('#endtime').val();
      var keyword = $.trim($("#searchkey").val());
      var status = $.trim($("#status").val());
      var typeid = $.trim($("#typeid").val());
      window.product_store.getProxy().setExtraParam('keyword',keyword);
      window.product_store.getProxy().setExtraParam('startdate',starttime);
      window.product_store.getProxy().setExtraParam('enddate',endtime);
      window.product_store.getProxy().setExtraParam('typeid',typeid);
      window.product_store.getProxy().setExtraParam('status',status);
      window.product_store.loadPage(1);
  }

  function modify(ordersn){
      var url = SITEURL+'{$prefix_url}/index/view/menuid/{$_GET['menuid']}/?ordersn='+ordersn;
      ST.Util.addTab('返佣详情',url,1)
  }

  //导出excel
  $(".btn_excel").click(function(){
      var url=SITEURL+"{$prefix_url}/index/excel";
      ST.Util.showBox('返佣明细导出Excel',url,580,350,function(){});
  })

 
</script>

</body>
</html>
